package jdbc;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class MyJDBCUtil {
    static Connection connection;
    public static Connection getConnection(){
        try{
            Properties properties =new Properties();
            InputStream in=MyJDBCUtil.class.getResourceAsStream("jdbc.properties");
            properties.load(in);
            Class.forName(properties.getProperty("driver"));
            if (connection==null){
                connection= DriverManager.getConnection(
                        properties.getProperty("url"),
                        properties.getProperty("username"),
                        properties.getProperty("password"));
            }
            System.out.println("JDBCOK");
            return connection;

        }catch (Exception ex){
            ex.printStackTrace();
        }
        System.out.println("错误");
        return null;
    }
}
